package com.xinke.edu.mypetadoption.entity;

//返回给前端的统一规范类
public class ResultBody<T> {
    int code; //统一返回码：200 成功  201失败
    String message; //提示语
    long TotalPage;

    T data;//数据


    public static <T> ResultBody<T> response(int code, String message, T data) {
        ResultBody resultBody = new ResultBody();
        resultBody.setCode(code);
        resultBody.setMessage(message);
        resultBody.setData(data);
        return resultBody;
    }

    public static <T> ResultBody<T> success(String message, T data) {
        return response(200, message, data);
    }

    public static <T> ResultBody<T> success(String message) {
        return response(200, message, null);
    }

    public static <T> ResultBody<T> success() {
        return response(200, "操作成功", null);
    }

    public static <T> ResultBody<T> fail(String message) {
        return response(201, message, null);
    }
    public static <T> ResultBody<T> fail() {
        return response(201, "操作失败", null);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public long getTotalPage() {
        return TotalPage;
    }

    public void setTotalPage(long totalPage) {
        TotalPage = totalPage;
    }
}


